package org.lex.keytool.ui.task;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.Box;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import org.lex.keytool.Swings;
import org.lex.keytool.core.service.KeyTools;
import org.lex.keytool.ui.common.FilePane;

public class DisplayKeyStorePane extends BaseTaskPane {
	public static void main(String[] args) {
		Swings.show(new DisplayKeyStorePane());
	}

	private JComboBox storeTypeComboBox;
	private JComboBox formatComboBox;
	private JLabel aliasLabel;
	private JLabel passwordLabel;
	private JLabel storeTypeLabel;
	private JLabel formatLabel;
	private FilePane filePane;
	private JPasswordField passwordField;
	private JTextField aliasTextField;

	public DisplayKeyStorePane() {
		initComponents();
	}

	private void initComponents() {
		setLayout(new GridBagLayout());
		GridBagConstraints gc;

		filePane = new FilePane(FilePane.Type.OPEN_FILE);
		filePane.setTitle("Key Store");
		gc = new GridBagConstraints();
		gc.gridx = 0;
		gc.gridy = 0;
		gc.gridwidth = 4;
		gc.fill = GridBagConstraints.HORIZONTAL;
		gc.anchor = GridBagConstraints.WEST;
		gc.weightx = 10.0;
		gc.insets = new Insets(0, 0, 5, 0);
		add(filePane, gc);

		aliasLabel = new JLabel("Alias");
		gc = new GridBagConstraints();
		gc.gridx = 0;
		gc.gridy = 1;
		gc.anchor = GridBagConstraints.BASELINE_LEADING;
		gc.insets = new Insets(0, 0, 5, 5);
		add(aliasLabel, gc);

		aliasTextField = new JTextField();
		gc = new GridBagConstraints();
		gc.gridx = 1;
		gc.gridy = 1;
		gc.fill = GridBagConstraints.HORIZONTAL;
		gc.anchor = GridBagConstraints.BASELINE_LEADING;
		gc.weightx = 5.0;
		gc.insets = new Insets(0, 0, 5, 5);
		add(aliasTextField, gc);

		passwordLabel = new JLabel("Password");
		gc = new GridBagConstraints();
		gc.gridx = 2;
		gc.gridy = 1;
		gc.anchor = GridBagConstraints.BASELINE_LEADING;
		gc.insets = new Insets(0, 0, 5, 5);
		add(passwordLabel, gc);

		passwordField = new JPasswordField();
		gc = new GridBagConstraints();
		gc.gridx = 3;
		gc.gridy = 1;
		gc.fill = GridBagConstraints.HORIZONTAL;
		gc.anchor = GridBagConstraints.BASELINE_LEADING;
		gc.weightx = 5.0;
		gc.insets = new Insets(0, 0, 5, 0);
		add(passwordField, gc);

		storeTypeLabel = new JLabel("Store Type");
		gc = new GridBagConstraints();
		gc.gridx = 0;
		gc.gridy = 2;
		gc.anchor = GridBagConstraints.BASELINE_LEADING;
		gc.insets = new Insets(0, 0, 0, 5);
		add(storeTypeLabel, gc);

		storeTypeComboBox = new JComboBox(KeyTools.getSupportKeyStoreTypes());
		gc = new GridBagConstraints();
		gc.gridx = 1;
		gc.gridy = 2;
		gc.fill = GridBagConstraints.HORIZONTAL;
		gc.anchor = GridBagConstraints.BASELINE_LEADING;
		gc.weightx = 5.0;
		gc.insets = new Insets(0, 0, 0, 5);
		add(storeTypeComboBox, gc);

		formatLabel = new JLabel("Output Format");
		gc = new GridBagConstraints();
		gc.gridx = 2;
		gc.gridy = 2;
		gc.anchor = GridBagConstraints.BASELINE_LEADING;
		gc.insets = new Insets(0, 0, 0, 5);
		add(formatLabel, gc);

		formatComboBox = new JComboBox(KeyTools.getSupportPrintFormats());
		gc = new GridBagConstraints();
		gc.gridx = 3;
		gc.gridy = 2;
		gc.fill = GridBagConstraints.HORIZONTAL;
		gc.anchor = GridBagConstraints.BASELINE_LEADING;
		gc.weightx = 5.0;
		add(formatComboBox, gc);

		// glue
		gc = new GridBagConstraints();
		gc.gridx = 0;
		gc.gridy = 3;
		gc.fill = GridBagConstraints.BOTH;
		gc.weightx = 10.0;
		gc.weighty = 10;
		gc.gridwidth = 3;
		add(Box.createGlue(), gc);
	}
}
